from collections import deque
# Definition for singly-linked list.
class ListNode(object):
    def __init__(self, x):
        self.val = x
        self.next = None

class Solution(object):
    def addTwoNumbers(self, l1, l2):
        """
        :type l1: ListNode
        :type l2: ListNode
        :rtype: ListNode
        """
        a = []
        b = []
        while l1:
            a.append(l1.val)
            l1 = l1.next
        while l2:
            b.append(l2.val)
            l2 = l2.next
        s1 = s2 = 0
        for i in range(len(a)):
            s1+=a[i] * pow(10,i)
        for i in range(len(b)):
            s2+=b[i] * pow(10,i)
        s1+=s2
        s1 = str(s1)
        m = []
        for i in range(len(s1)-1,-1,-1):
            m.append(s1[i])
        return m

l1 = ListNode(7)
l1.next = ListNode(2)
l1.next.next = ListNode(4)
l1.next.next.next = ListNode(3)

l2 = ListNode(5)
l2.next = ListNode(6)
l2.next.next = ListNode(4)

m = Solution()
s = m.addTwoNumbers(l1,l2)

print(s)
